/**
 * 枚举常量
 */
import tnx from '@/tnx.js';

export default class EnumConstant {
    caption = '';
    name = '';
    value = '';
    /**
     * @type {[String]}
     */
    scenes = [];

    constructor(name) {
        this.name = name;
        this.caption = name;
        this.value = name;
    }

    static of(object) {
        if (typeof object !== 'object') {
            return undefined;
        }
        let constant = new EnumConstant(object.name);
        constant.update(object);
        return constant;
    }

    update(object) {
        tnx.util.object.rewriteSimpleDefined(this, object);
        if (typeof object === 'object') {
            if (object.scenes) {
                this.scenes = [...object.scenes];
            }
        }
        return this;
    }

    clone() {
        return EnumConstant.of(this);
    }

}
